# Step 1: 下载 Node.js 安装程序
$nodeVersion = "18.15.0" # 您可以根据需要更改 Node.js 版本
$nodeUrl = "https://mirrors.huaweicloud.com/nodejs/v18.15.0/node-v18.15.0-x64.msi"

# 下载路径

$destinationPath = "$env:TEMP\node-v$nodeVersion-x64.msi"

# 下载程序

Write-Host "Downloading NodeJs..."
Invoke-WebRequest -Uri $nodeUrl -OutFile $destinationPath

# Step 2: 安装 Node.js
$msiPath = $destinationPath
Start-Process msiexec.exe -ArgumentList "/i", $msiPath, "/quiet", "/norestart" -NoNewWindow -Wait

# Step 3: 验证安装和环境变量
$nodePath = "C:\Program Files\nodejs"
$envPath = [System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)

if ($envPath -notcontains $nodePath) {
    $newEnvPath = "$envPath;$nodePath"
    [System.Environment]::SetEnvironmentVariable("Path", $newEnvPath, [System.EnvironmentVariableTarget]::Machine)
}


Write-Host "Node.js installation and configuration completed."
